var SLB_cnt = 0;
function showBox(url, type)
{
	if(url)
	{
		if(typeof(is_mobile) != 'undefined' && is_mobile == true)
		{
			$(document).ready(function() {
				$.mobile.ajaxEnabled = true;
				$('<a />').attr('href', url).attr({'data-rel':'dialog'}).click();
				$.mobile.ajaxEnabled = false;
			});
			return false;
		}

		$('html').css({'height':'100%'});
		$('#SLB_film').css({'top':0, 'left':0});
		if (document.documentElement.scrollHeight > document.body.scrollHeight)
		{
			$('#SLB_film').css('height', document.documentElement.scrollHeight);
		}
		else
		{
			$('#SLB_film').css('height', document.body.scrollHeight);
		}

		$('#SLB_content').show();
		$('#SLB_film').fadeTo('slow', 0.4);
		loading.css({top:$('html').scrollTop()+10+'px'}).show();

		var resize = (arguments[5]) ? arguments[5] : true;
		$('#slb_main').html("<iframe id='SLB_iframe' src='"+ url +"' width='"+ arguments[2] +"' height='"+ arguments[3] +"' class='SLB_center' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0' onload='tryReHeight("+resize+");'></iframe>");
		hideSelect();
		tryReHeight();
	}
	else
	{
		if(typeof(is_mobile) != 'undefined' && is_mobile == true)
		{
			$('.ui-dialog').dialog('close');
			return false;
		}
		$('#SLB_content').hide();
		$('#SLB_film').hide();
		$('#SLB_film').css({'width':'100%', 'height':'100%'});
		$('#slb_main').html("");
		loading.hide();
		showSelect();
		SLB_cnt = 0;
	}
}

function SLB_setCenter(obj)
{
	if(obj)
	{
		var h = (window.innerHeight || self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
		var w = (window.innerWidth || self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth);
		var l = ((window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft) + ((w-(obj.width||parseInt(obj.style.width)||obj.offsetWidth))/2));
		var t = ((window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop) + ((h-(obj.height||parseInt(obj.style.height)||obj.offsetHeight))/2));
		if((obj.width||parseInt(obj.style.width)||obj.offsetWidth) >= w) l = 0;
		if((obj.height||parseInt(obj.style.height)||obj.offsetHeight) >= h) t = (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
		$('#SLB_content').css('left', l-32);
		if(SLB_cnt == 0)
		{
			$('#SLB_content').css('top', t);
			if($('#SLB_content').get(0).offsetHeight >= h-20)
			{
				SLB_cnt ++;
			}
		}
		if(!arguments[1])
		{
			loading.hide();
		}
		else
		{
			$(obj).css({'left':l, 'top':t});
		}
	}
}

function hideSelect()
{
	$('select').each(function() {
		$(this).css('visibility', 'hidden');
	});
}

function showSelect()
{
	$('select').each(function() {
		$(this).css('visibility', 'visible');
	});
}

function tryReHeight(sign)
{
	var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	var FFextraHeight = parseFloat(getFFVersion)>=0.1? 16 : 0;
	var currentfr = $('#SLB_iframe').get(0);
	if(sign == true)
	{
		try {
			if(currentfr.Document && currentfr.Document.body.scrollHeight)
			{
				setIframeSize(currentfr.Document.body.scrollHeight);
			}
			else if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight)
			{
				setIframeSize(currentfr.contentDocument.body.offsetHeight+FFextraHeight);
			}
		} catch(e) {}
	}
	else
	{
		SLB_setCenter($('#slb_main').get(0));
	}
	try {
		currentfr.contentWindow.focus();
	} catch(e) {}
}

function setIframeSize(h, w)
{
	SLB_cnt = 0;
	if(w)
	{
		$('#SLB_iframe').attr('width', w);
	}
	if(h)
	{
		$('.slb_left').css('height', h);
		$('.slb_right').css('height', h);
		$('#SLB_iframe').attr('height', h);
	}
	SLB_setCenter($('#slb_main').get(0));
}


$(document).ready(function()
{
	var prevOnScroll = window.onscroll;
	window.onscroll = function ()
	{
		if(prevOnScroll != undefined) prevOnScroll();
		if (document.documentElement.scrollHeight > document.body.scrollHeight)
		{
			$('#SLB_film').css('height', document.documentElement.scrollHeight);
		}
		else
		{
			$('#SLB_film').css('height', document.body.scrollHeight);
		}
		$('#SLB_film').css('width', document.body.scrollWidth);
		SLB_setCenter($('#slb_main').get(0));
	}

	var prevOnResize = window.onresize;
	window.onresize = function ()
	{
		if(prevOnResize != undefined) prevOnResize();
		if (document.documentElement.scrollHeight > document.body.scrollHeight)
		{
			$('#SLB_film').css('height', document.documentElement.scrollHeight);
		}
		else
		{
			$('#SLB_film').css('height', document.body.scrollHeight);
		}

		$('#SLB_film').css('width', document.body.offsetWidth);
		SLB_setCenter($('#slb_main').get(0));
	}
});